<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>消息中心</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/layadmin/style/default.css" media="all">
    <link rel="stylesheet" href="/static/plugins/editor/wangeditor/dist/wangEditor.css" media="all">
</head>
<body>
    <div class="layui-fluid" id="LAY-app-message">
        <div class="layui-card">
            <div class="layui-tab layui-tab-brief">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">产品名称<span style="color: red;">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" value="{$mess.name}" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">单位</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="unit" value="{$mess.unit}" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">售价</label>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="price" value="{$mess.price}" placeholder="￥" autocomplete="off" class="layui-input" >
                                    </div>
                                    <div class="layui-form-mid">原价</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="oprice" value="{$mess.oprice}" placeholder="￥" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">标签</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mark" value="{$mess.mark}" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">关键字</label>
                                <div class="layui-input-block">
                                    <input type="text" name="tags" value="{$mess.tags}" class="layui-input">
                                </div>
                            </div>                            
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">产品简介</label>
                                <div class="layui-input-block">
                                    <textarea name="summary" class="layui-textarea">{$mess.summary}</textarea>
                                </div>
                            </div>
                            
                            <!--<div class="layui-form-item">-->
                            <!--    <div class="layui-inline">-->
                            <!--        <label class="layui-form-label">库存</label>-->
                            <!--        <div class="layui-input-inline" style="width: 100px;">-->
                            <!--            <input type="text" name="stock" value="{$mess.stock}" placeholder="" autocomplete="off" class="layui-input">-->
                            <!--        </div>-->
                            <!--        <div class="layui-form-mid">销量</div>-->
                            <!--        <div class="layui-input-inline" style="width: 100px;">-->
                            <!--            <input type="text" name="sales" value="{$mess.sales}" placeholder="" autocomplete="off" class="layui-input">-->
                            <!--        </div>-->
                            <!--    </div>-->
                            <!--</div>-->
                           <!--  <div class="layui-form-item">
                                <label class="layui-form-label">香型</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="flavor" value="{$mess.flavor|default='酱香型'}" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">净含量</label>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="netwt" value="{$mess.netwt|default='500'}" placeholder="￥" autocomplete="off" class="layui-input" >
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">ml</div>
                                    <div class="layui-form-mid">酒精度</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="vol" value="{$mess.vol|default='53'}" placeholder="￥" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">vol</div>
                                </div>
                            </div> -->
                            
                            <!-- <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">产地</label>
                                <div class="layui-input-block">
                                    <input type="text" name="address" value="{$mess.address|default='贵州省仁怀市茅台镇'}" class="layui-input">
                                </div>
                            </div> -->
                            <!--<div class="layui-form-item">-->
                            <!--    <label class="layui-form-label">原料</label>-->
                            <!--    <div class="layui-input-block">-->
                            <!--        <input type="text" name="material" value="{$mess.material|default='水、高粱、小麦'}" class="layui-input">-->
                            <!--    </div>-->
                            <!--</div>-->
                            <!--<div class="layui-form-item layui-form-text">-->
                            <!--    <label class="layui-form-label">厂家</label>-->
                            <!--    <div class="layui-input-block">-->
                            <!--        <input type="text" name="factory" value="{$mess.factory}" class="layui-input">-->
                            <!--    </div>-->
                            <!--</div>-->
            <!--                 <div class="layui-form-item">
                                <label class="layui-form-label">净含量<span style="color: red;">*</span></label>
                                <div class="layui-input-inline">
                                    <input type="text" name="netwt" value="{$mess.netwt}" placeholder="500" autocomplete="off" class="layui-input" lay-verify="required">
                                </div>
                                <div class="layui-form-mid layui-word-aux">ml</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">酒精度<span style="color: red;">*</span></label>
                                <div class="layui-input-inline">
                                    <input type="text" name="vol" value="{$mess.vol}" placeholder="53" autocomplete="off" class="layui-input" lay-verify="required">
                                </div>
                                <div class="layui-form-mid layui-word-aux">vol</div>
                            </div> -->
                            <!--<div class="layui-form-item">-->
                            <!--    <label class="layui-form-label">箱规</label>-->
                            <!--    <div class="layui-input-inline">-->
                            <!--        <input type="text" name="pack" value="{$mess.pack}" placeholder="" autocomplete="off" class="layui-input">-->
                            <!--    </div>-->
                            <!--    <div class="layui-form-mid layui-word-aux">常见规格有：1*4，1*6，1*12</div>-->
                            <!--</div>-->
                            <!--<div class="layui-form-item layui-form-text">-->
                            <!--    <label class="layui-form-label">酿造工艺</label>-->
                            <!--    <div class="layui-input-block">-->
                            <!--        <input type="text" name="technology" value="{$mess.technology}" class="layui-input">-->
                            <!--    </div>-->
                            <!--</div>-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">封面图</label>
                                <div class="layui-input-inline" style="width:30%;">
                                    <input type="text" name="thumb" id="filepath" value="{$mess.thumb}" subId="{$mess.thumb}" class="layui-input">
                                    <!-- <input type="hidden" name="annexes">                                  -->
                                </div>
                                <div class="layui-form-mid layui-word-aux" style="padding:0px !important;">
                                    <button type="button" class="layui-btn" id="test-upload-type1"><i class="layui-icon"></i>上传图片</button>
                                    </div>
                                <!-- <div class="layui-form-mid layui-word-aux">仅支持上传pdf格式</div> -->
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">轮播图</label>
                                <div class="layui-input-inline">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="test-upload-more"><i class="layui-icon"></i>多图上传</button>
                                    </div>
                                </div>
                                <div class="layui-form-mid layui-word-aux">点击图片有想象不到的效果哟！</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <input type="hidden" name="images" id="images"  value="{$mess.images}">
                                        <blockquote class="layui-elem-quote layui-quote-nm margin-top-10">
                                            <div class="layui-upload-list" id="test-upload-more-list">
                                                {volist name="$mess.photos" id="v"}
                                                <a class="album-list">
                                                    <img src="{$v.urlpath}" alt="{$v.id}" class="layui-upload-img"   >
                                                </a>
                                                {/volist}
                                            </div>
                                        </blockquote>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">产品详情<span style="color: red;">*</span></label>
                                <div class="layui-input-block" id="wangEditor">{$mess.content}</div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">META关键词</label>
                                <div class="layui-input-block">
                                    <textarea name="keywords" class="layui-textarea" placeholder="多个关键词用英文状态 , 号分割">{$mess.keywords}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">META描述</label>
                                <div class="layui-input-block">
                                    <textarea name="descript" class="layui-textarea">{$mess.descript}</textarea>
                                </div>  
                            </div>
                            <div class="layui-form-item" pane="">
                                <label class="layui-form-label">推荐</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="is_home" lay-skin="primary" title="首页推荐" {if condition="$mess.is_home eq 1"}checked{/if}>
                                    <input type="checkbox" name="is_top" lay-skin="primary" title="置顶" {if condition="$mess.is_top eq 1"}checked{/if}>
                                    <input type="checkbox" name="is_hot" lay-skin="primary" title="热门" {if condition="$mess.is_hot eq 1"}checked{/if}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <input type="hidden" name="updid" value="{$mess.id}">
                                    <input type="hidden" name="cid" value="{$fid}">
                                    <button class="layui-btn" lay-submit lay-filter="save_product">确认保存</button>
                                    <button class="layui-btn layui-btn-primary formCancel" >取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>  
    </div>
    <script src="/static/layadmin/layui/layui.js"></script>
    <script src="/static/plugins/editor/wangeditor/dist/wangEditor.min.js"></script>
    <script>
        const E = window.wangEditor;//初始化
        const editor = new E('#wangEditor');//实例化
        // editor.config.height = 500;//编辑器高度
        editor.config.pasteFilterStyle = false;//取消粘贴内容格式过滤
        editor.config.uploadImgServer = '/admin/base/upload_file';//上传文件接口
        editor.config.uploadFileName = 'file';//上传文件名
        editor.config.uploadImgMaxLength = 1; 
        editor.config.uploadVideoServer = '/admin/base/upload_video';//上传视频接口
        editor.config.uploadVideoMaxSize = 50 * 1024 * 1024;  // 50m，上传视频大小
        editor.config.uploadVideoAccept = ['mp4'];//上传视频格式
        editor.config.uploadVideoName = 'videox';//上传视频名
        editor.create();
    layui.config({
        base: '/static/layadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'upload', 'form', 'layedit'], function() {
        var $ = layui.jquery,
            upload = layui.upload,
            layedit = layui.layedit,
            form = layui.form;
        // layedit.build('content');layui自带富文本编辑器

        var uploadInst = upload.render({
            elem: '#test-upload-type1',
            url: '/admin/base/default_upload', //改成您自己的上传接口
            accept: 'file',
            // acceptMime:'application/msword,image/gif,image/x-icon,image/jpeg,video/mpeg4,application/pdf,application/x-png,application/x-ppt,application/x-xls,application/x-ico,audio/mp3,image/png,application/vnd.ms-powerpoint,application/x-ppt,text/plain,application/vnd.ms-excel' ,
            acceptMime: 'image/jpeg,image/gif,image/png,image/x-icon',
            size: 2048, //限制文件大小，单位 KB
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result) {});
            },
            done: function(res) {
                // console.log(res);
                if (res.code > 0) {
                    
                    layer.msg(res.msg, { icon: 6 }, function() {
                        $('#filepath').val(res.filename);
                    });
                } else {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });
        //多图片上传

        upload.render({
            elem: '#test-upload-more',
            url: '/admin/product/default_upload', //改成您自己的上传接口
            accept: 'file',
            multiple: true,
            // acceptMime:'application/msword,image/gif,image/x-icon,image/jpeg,video/mpeg4,application/pdf,application/x-png,application/x-ppt,application/x-xls,application/x-ico,audio/mp3,image/png,application/vnd.ms-powerpoint,application/x-ppt,text/plain,application/vnd.ms-excel' ,
            acceptMime: 'image/jpeg,image/gif,image/png,image/x-icon',
            size: 2048, //限制文件大小，单位 KB
            before: function(obj) {
                //预读本地文件示例，不支持ie8

                obj.preview(function(index, file, result) {
                    // console.log(file);
                    // $('#test-upload-more-list').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            },
            done: function(res) {
                // console.log(res);
                if (res.code > 0) {
                    layer.msg(res.msg, { icon: 6 }, function() {
                        $('#test-upload-more-list').append('<a class="album-list"><img src="' + res.filename + '" alt="' + res.data.id + '" class="layui-upload-img"  lay-submit lay-filter="delImg"></a>')
                            var images_filename = $('#images').val();
                        if (images_filename) {
                            $('#images').val(images_filename + ',' + res.data.id);
                        } else {
                            $('#images').val(res.data.id);
                        }
                    })

                    // return layer.msg('上传成功');
                } else {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });
        //监听提交
        form.on('submit(save_product)', function(data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
            // layer.msg('表单已提交');
            // var thumb = $("#filepath").attr("subId");    
            var content=editor.txt.html();   
            // var updata=title: field.title, summary: field.summary, price: field.price, oprice: field.oprice, stock: field.stock, sales: field.sales, flavor: field.flavor, address: field.address, material: field.material, factory: field.factory, netwt: field.netwt, vol: field.vol, pack: field.pack, technology: field.technology, thumb: thumb, cid: field.cid, images: field.images, content: field.content, keywords: field.keywords, descript: field.descript, is_home: field.is_home, is_top: field.is_top, is_hot: field.is_hot;
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post('/admin/product/addMessDone/updid/' + field.updid, { name: field.name,unit: field.unit, tags: field.tags,price: field.price,oprice: field.oprice,mark: field.mark, thumb: field.thumb, cid: field.cid, images: field.images,summary: field.summary, content: content, keywords: field.keywords, descript: field.descript, is_home: field.is_home, is_top: field.is_top, is_hot: field.is_hot }, function(res) {
                res = $.parseJSON(res);
                console.log(res.code);
                if (res.code == 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function() {
                        // parent.layui.table.reload('list-table'); //重载表格
                        parent.location.reload();
                        parent.layer.close(index); //再执行关闭                    
                        // window.location.reload();
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, time: 2000 });
                }
            });
        });
         $('.formCancel').on('click', function () {
          var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
          parent.layer.close(index); //再执行关闭 
        });
         $("#test-upload-more-list").on("click",".album-list",function(){
            var tthis=$(this);
            var delId=tthis.children("img").attr("alt");
            var thumb = tthis.children("img").attr("src");
            var images = $("#images").val();
            console.log(delId);
            layer.confirm('你要做什么呢？', {
              btn: ['看大图','删除','关闭'] //按钮
            }, function(index){
                window.open(thumb); 
                layer.close(index);
            }, function(){
              layer.msg('真的删除吗？', {
                time: 20000, //20s后自动关闭
                btn: ['确定', '取消'],
                yes:function(index){                    
                    $.get('{:url("admin/product/img_del")}',{id:delId},function(ret){
                      ret = $.parseJSON(ret);
                      console.log(ret);
                      if (ret.code == 0) { //添加失败
                          layer.msg(ret.msg, { icon: 5 })
                      } else { //添加成功
                          layer.msg(ret.msg, { icon: 6 }, function() {
                              tthis.remove();
                              var imgArry = images.split(",");
                                for (var i = 0; i < imgArry.length; i++) {
                                    if (delId == imgArry[i]) {
                                        imgArry.splice(i, 1);
                                    }
                                }
                                imgArry = imgArry.join(",");
                                $("#images").val(imgArry);
                              // obj.del();
                          })
                      }
                  }); 
                    layer.close(index);
                }
              });
            },function(index){
                layer.close(index);
            });
         });
         $('.formCancel').on('click', function () {
          var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
          parent.layer.close(index); //再执行关闭 
        });
    
        $('#filepath').on('click', function() {
            var thumb = $(this).val();

            if (thumb) {
                window.open(thumb);
            }
        });

    });
    </script>
</body>

</html>